from service.func.read_bdf import read_bdf
from service.func.read_msh import read_msh
from service.func.read_vtk import read_vtk
from service.func.read_gy import read_gy
from service.func.read_eb_data import read_eb_data
from service.func.read_vtp import read_vtp
from service.func.read_vtu import read_vtu
from service.func.read_cgns import read_cgns


def check_file_type(file_type, ext):
    if file_type == "bdf" and ext != "bdf":
        return False
    if file_type == "cgns" and ext != "cgns":
        return False
    if file_type == "vtk" and ext != "vtk":
        return False
    if file_type == "vtu" and ext != "vtu":
        return False
    if file_type == "vtp" and ext != "vtp":
        return False
    if file_type == "eb_dat" and ext != "dat":
        return False
    if file_type == "msh" and ext != "msh":
        return False
    return True


def file_load(service, options):
    url = options.get("path")
    file_type = options.get("FileType")
    ext = url.split(".")[-1]
    if not check_file_type(file_type, ext):
        return None
    append = options.get("append", None)
    uid = None
    if not append:
        # 先清空所有对象
        service.app.remove_all()
    match file_type:
        case "gy":
            read_gy(service, url)
        case "eb_dat":
            read_eb_data(service, url)
        case "vtk":
            uid = read_vtk(service, options)
        case "vtu":
            read_vtu(service, options)
        case "vtp":
            uid = read_vtp(service, options)
        case "cgns":
            uid = read_cgns(service, options)
        case "msh":
            uid = read_msh(service, options)
        case "bdf":
            uid = read_bdf(service, options)
    return uid
